package com.mycontacts;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class ContactsSQLiteHelper extends SQLiteOpenHelper {
//CREATE  TABLE "main"."Contacts" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "name" VARCHAR, "address" VARCHAR, "cell" VARCHAR, "alt" VARCHAR, "email" VARCHAR, "comments" TEXT, "cat1" BOOL, "cat2" BOOL, "cat3" BOOL, "cat4" BOOL, "cat5" BOOL)
	public static final String TABLE_CONTACTS = "contacts";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_NAME = "name";
	public static final String COLUMN_ADDRESS = "address";
	public static final String COLUMN_CELL = "cell";
	public static final String COLUMN_ALT = "alt";
	public static final String COLUMN_EMAIL = "email";
	public static final String COLUMN_COMMENTS = "comments";
	public static final String COLUMN_CAT1 = "cat1";
	public static final String COLUMN_CAT2 = "cat2";
	public static final String COLUMN_CAT3 = "cat3";
	public static final String COLUMN_CAT4 = "cat4";
	public static final String COLUMN_CAT5 = "cat5";
	
	private static final String DATABASE_NAME = "mycontacts.db";
	private static final int DATABASE_VERSION = 1;
	
	private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_CONTACTS + "(" + 
			COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
			COLUMN_NAME + " VARCHAR, " +
			COLUMN_ADDRESS + " VARCHAR, " +
			COLUMN_CELL + " VARCHAR, " + 
			COLUMN_ALT + " VARCHAR, " + 
			COLUMN_EMAIL + " VARCHAR, " + 
			COLUMN_COMMENTS + " VARCHAR, " + 
			COLUMN_CAT1 + " BOOL, " +
			COLUMN_CAT2 + " BOOL, " +
			COLUMN_CAT3 + " BOOL, " +
			COLUMN_CAT4 + " BOOL, " +
			COLUMN_CAT5 + " BOOL, ";
	
	public ContactsSQLiteHelper(Context context){
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	 @Override
	 public void onCreate(SQLiteDatabase database) {
	    database.execSQL(DATABASE_CREATE);
	  }
	
	  @Override
	  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	    Log.w(ContactsSQLiteHelper.class.getName(),
	        "Upgrading database from version " + oldVersion + " to "
	            + newVersion + ", which will destroy all old data");
	    db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
	    onCreate(db);
	  }
			
}
